var EnterpriseDetail = function() {
	var handleValidation = function() {
		return {
			init : function() {
				var enterpriseID = $('#enterpriseID').val();

				// 基本信息点击事件
				$('#detailLi').unbind("click").click(function() {
					$('#detailLi').addClass('active');
					$('#detailContent').css('display', 'block');

					$('#teamLi').removeClass('active');
					$('#teamContent').css('display', 'none');
					$('#businessLi').removeClass('active');
					$('#businessContent').css('display', 'none');
					$('#financialLi').removeClass('active');
					$('#financialContent').css('display', 'none');
					$('#attachmenttLi').removeClass('active');
					$('#attachmenttContent').css('display', 'none');
				});
				// 团队介绍点击事件
				$('#teamLi')
						.unbind("click")
						.click(
								function() {
									$('#teamLi').addClass('active');
									$('#teamContent').css('display', 'block');

									$($('.summernote')[1])
											.summernote(
													{
														height : 400,
														toolbar : [
																['style',[ 'style' ] ],
																['style',['bold','italic','underline','clear' ] ],
																['fontsize',[ 'fontsize' ] ],
																['fontname',[ 'fontname' ] ],
																['color',[ 'color' ] ],
																['para',['ul','ol','paragraph' ] ],
																['height',[ 'height' ] ],
																['table',[ 'table' ] ],
																['insert',['picture','link' ] ],
																['help',[ 'help' ] ] ],
														onImageUpload : function(files, editor,$editable) {
															sendFile(files,editor,$editable);
														},
														onblur : function(e) {
															validateContent();
														},
														onfocus : function(e) {
															validateContent();
														},
														onChange : function(contents,$editable) {
															validateContent();
														},
														bFullscreen : false,

													});

									$('#detailLi').removeClass('active');
									$('#detailContent').css('display', 'none');
									$('#businessLi').removeClass('active');
									$('#businessContent').css('display', 'none');
									$('#financialLi').removeClass('active');
									$('#financialContent').css('display','none');
									$('#attachmenttLi').removeClass('active');
									$('#attachmenttContent').css('display','none');
								});
				// 商业模式点击事件
				$('#businessLi')
						.unbind("click")
						.click(
								function() {
									$('#businessLi').addClass('active');
									$('#businessContent').css('display','block');

									// 富文本编辑器
									for (var i = 2; i < 8; i++) {
										$($('.summernote')[i]).summernote(
														{
															height : 400,
															toolbar : [
																	['style',[ 'style' ] ],
																	['style',['bold','italic','underline','clear' ] ],
																	['fontsize',[ 'fontsize' ] ],
																	['fontname',[ 'fontname' ] ],
																	['color',[ 'color' ] ],
																	['para',['ul','ol','paragraph' ] ],
																	['height',[ 'height' ] ],
																	['table',[ 'table' ] ],
																	['insert',['picture','link' ] ],
																	['help',[ 'help' ] ] ],
															onImageUpload : function(files, editor,$editable) {
																sendFile(files,editor,$editable);
															},
															onblur : function(e) {
																validateContent();
															},
															onfocus : function(e) {
																validateContent();
															},
															onChange : function(contents,$editable) {
																validateContent();
															},
															bFullscreen : false,

														});
									}

									$('#detailLi').removeClass('active');
									$('#detailContent').css('display', 'none');
									$('#teamLi').removeClass('active');
									$('#teamContent').css('display', 'none');
									$('#financialLi').removeClass('active');
									$('#financialContent').css('display','none');
									$('#attachmenttLi').removeClass('active');
									$('#attachmenttContent').css('display','none');
								});
				// 财务数据点击事件
				$('#financialLi')
						.unbind("click")
						.click(
								function() {
									$('#financialLi').addClass('active');
									$('#financialContent').css('display','block');

									for (var i = 8; i < 10; i++) {
										$($('.summernote')[i]).summernote(
														{
															height : 400,
															toolbar : [
																	['style',[ 'style' ] ],
																	['style',['bold','italic','underline','clear' ] ],
																	['fontsize',[ 'fontsize' ] ],
																	['fontname',[ 'fontname' ] ],
																	['color',[ 'color' ] ],
																	['para',['ul','ol','paragraph' ] ],
																	['height',[ 'height' ] ],
																	['table',[ 'table' ] ],
																	['insert',['picture','link' ] ],
																	['help',[ 'help' ] ] ],
															onImageUpload : function(files, editor,$editable) {
																sendFile(files,editor,$editable);
															},
															onblur : function(e) {
																validateContent();
															},
															onfocus : function(e) {
																validateContent();
															},
															onChange : function(contents,$editable) {
																validateContent();
															},
															bFullscreen : false,

														});
									}

									$('#detailLi').removeClass('active');
									$('#detailContent').css('display', 'none');
									$('#teamLi').removeClass('active');
									$('#teamContent').css('display', 'none');
									$('#businessLi').removeClass('active');
									$('#businessContent').css('display', 'none');
									$('#attachmenttLi').removeClass('active');
									$('#attachmenttContent').css('display','none');
								});
				// 附件点击事件
				$('#attachmenttLi').unbind("click").click(function() {
					$('#attachmenttLi').addClass('active');
					$('#attachmenttContent').css('display', 'block');

					$('#detailLi').removeClass('active');
					$('#detailContent').css('display', 'none');
					$('#teamLi').removeClass('active');
					$('#teamContent').css('display', 'none');
					$('#businessLi').removeClass('active');
					$('#businessContent').css('display', 'none');
					$('#financialLi').removeClass('active');
					$('#financialContent').css('display', 'none');
				});

				// 富文本编辑器
				$($('.summernote')[0]).summernote(
						{
							height : 400,
							toolbar : [
										['style',[ 'style' ] ],
										['style',['bold','italic','underline','clear' ] ],
										['fontsize',[ 'fontsize' ] ],
										['fontname',[ 'fontname' ] ],
										['color',[ 'color' ] ],
										['para',['ul','ol','paragraph' ] ],
										['height',[ 'height' ] ],
										['table',[ 'table' ] ],
										['insert',['picture','link' ] ],
										['help',[ 'help' ] ] ],
							onImageUpload : function(files, editor, $editable) {
								sendFile(files, editor, $editable);
							},
							onblur : function(e) {
								validateContent1();
							},
							onfocus : function(e) {
								validateContent1();
							},
							onChange : function(contents, $editable) {
								validateContent1();
							},
							bFullscreen : false,

						});

				var detailContentForm = $('#detailContentForm');
				//基本信息提交规格效验
				detailContentForm.validate({
                    focusInvalid: true,
                    rules: {
                    	enterpriseName: {
                            required: true,
                        },
                        legalPerson: {
                            required: true,
                        },
                        mobile: {
                            required: true,
                            number:true,
                        },
                    },
                    messages: {
                    	enterpriseName: {
                            required: "账号不能为空！",
                        },
                    },
                    success: function(label, element) {
                        var icon = $(element).parent('.input-icon').children('i');
                        $(element).closest('.form-group').removeClass('has-error').addClass('has-success'); // set success class to the control group
                        icon.removeClass("fa-warning").addClass("fa-check");
                    },
                    submitHandler: function(form) {
                        var form = $("form#addDetailForm").serializeJSON();
                        var assetAllocationId = $('#assetAllocationId').val();
                        if (assetAllocationId == '') {
                        	bootbox.alert("请先添加资产配资");
                        	return;
                        }
                        var js = form.replace('}', ',');
                        var json = js + '"assetAllocationId" : "' + assetAllocationId + '"}'; 
                        $('#addConfirm').attr('disabled', true);
                        $.ajax({
                            type: "post",
                            contentType: "application/json; charset=UTF-8",
                            url: ctx + "/assetAllocation/doAddDetail",
                            data: json,
                            dataType: "json",
                            success: function(msg) {
                                if (msg.code == 1) {
                                    bootbox.alert("新增成功！");
                                    modal.modal('hide');
                                    oTable.fnDraw(false);
                                } else {
                                    bootbox.alert(msg.message);
                                }
                                $('#addConfirm').attr('disabled', false);
                            },
                            error: function(msg) {
                                bootbox.alert(msg.message);
                                modal.modal('hide');
                                $('#addConfirm').attr('disabled', false);
                            }
                        });
                    }
                });
				
				//基本信息提交
				$('#detailContentSubmit').unbind("click").click(function() {
                   console.log("基本信息提交");
                   var form = $("#detailContentForm").value;
                   console.log(form);
                   var enterpriseName = $("#enterpriseName").value;
                   console.log(enterpriseName);
                });
				//团队介绍 提交
				$('#teamContentSubmit').unbind("click").click(function() {
                   console.log("团队介绍 提交");
                });
				//商业模式提交
				$('#businessContentSubmit').unbind("click").click(function() {
                   console.log("商业模式提交");
                });
				//财务数据提交
				$('#financiaContentSubmit').unbind("click").click(function() {
                   console.log("财务数据提交");
                });
				
	            
				// 表格初始化 --待完成
				/*var oTable = $('#teamContentEditable')
						.dataTable(
								{
									"autoWidth" : false,
									"paginate" : false, // 翻页功能
									"lengthChange" : false, // 改变每页显示数据数量
									"info" : false,// 页脚信息
									"language" : {
										"zeroRecords" : "数据为空"
									},
									"columnDefs" : [
											{
												"data" : null,
												'sortable' : false,
												"defaultContent" : "<center>--</center>",
												"targets" : [ 0 ]
											},
											{
												"data" : null,
												'sortable' : false,
												"defaultContent" : "<center>--</center>",
												"targets" : [ 1 ]
											},
											{
												"data" : null,
												'sortable' : false,
												"defaultContent" : "<center>--</center>",
												"targets" : [ 2 ]
											},
											{
												"data" : null,
												'sortable' : false,
												"defaultContent" : "<center>--</center>",
												"targets" : [ 3 ]
											},
											{
												"data" : null,
												'sortable' : false,
												"defaultContent" : "<center>--</center>",
												"targets" : [ 4 ]
											},
											{
												"data" : null,
												'sortable' : false,
												"defaultContent" : "<center>--</center>",
												"targets" : [ 5 ]
											},
											{
												"data" : null,
												'sortable' : false,
												"defaultContent" : "<center>--</center>",
												"targets" : [ 6 ]
											} ],
									"columns" : [ 
									              {	"data" : "employeeName"}, 
									              {"data" : "employeePosition"},
									              {"data" : "totalShares"},
									              {"data" : "fullTime"}, 
									              {"data" : "actualContributiveAmount"}, 
									              {"data" : "introduction"} 
									            ],
									"filter" : false,
									"processing" : false,
									"serverSide" : true,
									"ajaxSource" : ctx + "/project/employeeList/" + enterpriseID,
									"serverMethod" : "post",
									"fnRowCallback" : function(nRow, aData, displayIndex) {
										nRow.children[0].id = aData.id;
										$('td:eq(0)', nRow).html(++displayIndex);
										$(nRow).appendTo($('#modelEditable_tbody'));
										return nRow;
									},
									"fnServerData" : function(ajaxSource,
											dataSet, fnCallback) {
										$.ajax({
													"contentType" : "application/json; charset=UTF-8",
													"dataType" : 'json',
													"type" : "POST",
													"url" : ajaxSource,
													"data" : "",
													"success" : fnCallback
												});
									},
								});*/

			}

		};
	}();

	return {
		init : function() {
			handleValidation.init();
		}
	};
}();
